﻿module Sustainalytics.Shell {

    import Common = Sustainalytics.Common;
    import Navigation = Sustainalytics.Navigation;
    import Routing = Sustainalytics.Routing;


    var mod = angular.module(shellModuleName);


    // configure module
    mod.config([Sustainalytics.Routing.routingServiceName + 'Provider', '$httpProvider', (routingProvider: Routing.IRoutingServiceProvider, $httpProvider) => {

        $httpProvider.interceptors.push(Sustainalytics.Authentication.authenticationHttpInterceptorName);

        routingProvider
            .when('/',
            {
                templateUrl: '/views/Home.html', controller: 'HomeController'
            },
            null,
            ['Home', 'GCCS.Security', 'PI.Security', 'ScreeningTool.Security'])

            .when('/events',
            {
                templateUrl: '/views/Event/EventList.html', controller: 'EventListController'
            },
            null,
            ['CompanySearch', 'LRTM', 'Events', 'Pager', 'ScrollPager', 'GCCS.Security', 'PI.Security', 'ScreeningTool.Security'])

            .when('/events/date/:eventsDate',
            {
                templateUrl: '/views/Event/EventView.html', controller: 'EventViewController'
            },
            null,
            ['CompanySearch', 'LRTM', 'Events', 'Pager', 'ScrollPager', 'GCCS.Security', 'PI.Security', 'ScreeningTool.Security'])

            .when('/mostactivereports',
            {
                templateUrl: '/views/MostActiveReports/List.html', controller: 'MostActiveReportController', controllerAs: 'mar'
            },
            null,
            ['CompanySearch', 'LRTM', 'MostActiveReports', 'Pager', 'ScrollPager', 'Company', 'GCCS.Security', 'PI.Security', 'ScreeningTool.Security'])

            .when('/mostrecentactivity',
            {
                templateUrl: '/views/MostRecentActivity/List.html', controller: 'MostRecentActivityController', controllerAs: 'mra'
            },
            null,
            ['CompanySearch', 'LRTM', 'MostRecentActivity', 'Pager', 'ScrollPager', 'Company', 'GCCS.Security', 'PI.Security', 'ScreeningTool.Security'])

            .when('/news',
            {
                templateUrl: '/views/News/NewsList.html', controller: 'NewsListController'
            },
            null,
            ['CompanySearch', 'LRTM', 'News', 'Pager', 'ScrollPager', 'GCCS.Security', 'PI.Security', 'ScreeningTool.Security'])

            .when('/news/:newsId',
            {
                templateUrl: '/views/News/NewsView.html', controller: 'NewsViewController'
            },
            null,
            ['CompanySearch', 'LRTM', 'News', 'Pager', 'ScrollPager', 'GCCS.Security', 'PI.Security', 'ScreeningTool.Security'])

            .when('/insights',
            {
                templateUrl: '/views/Insights/InsightsList.html', controller: 'InsightsListController'
            },
            null,
            ['CompanySearch', 'LRTM', 'Insights', 'Pager', 'ScrollPager', 'GCCS.Security', 'PI.Security', 'ScreeningTool.Security'])

            .when('/insights/:id',
            {
                templateUrl: '/views/Insights/InsightsView.html', controller: 'InsightsViewController'
            },
            null,
            ['CompanySearch', 'LRTM', 'Insights', 'Pager', 'ScrollPager', 'GCCS.Security', 'PI.Security', 'ScreeningTool.Security'])

            .when('/portfolios',
            {
                templateUrl: '/views/Portfolio/Portfolios.html', controller: 'PortfolioListController'
            },
            new Routing.RouteSecurity().addResource({ verb: 'GET', resource: 'api/v1/portfolios', parameters: [{ key: 'shortName', value: 'portfoliomanagement' } ] }),
            ['CompanySearch', 'LRTM', 'Portfolio', 'Pager', 'ScrollPager', 'Company', 'GCCS.Security', 'PI.Security', 'ScreeningTool.Security'])

            .when('/portfolios/:id',
            {
                templateUrl: '/views/Portfolio/PortfolioOverview.html', controller: 'PortfolioOverviewController'
            },
            new Routing.RouteSecurity().addResource({ verb: 'GET', resource: 'api/v1/portfolios', parameters: [{ key: 'shortName', value: 'portfoliomanagement' }] }),
            ['CompanySearch', 'LRTM', 'Portfolio', 'Pager', 'ScrollPager', 'Company', 'GCCS.Security', 'PI.Security', 'ScreeningTool.Security'])

            .when('/research/company',
            {
                templateUrl: '/views/Research/Company/CompanyList.html', controller: 'CompanyListController'
            },
            new Routing.RouteSecurity().addResource({verb: 'GET', resource: 'api/v1/companies', parameters: [{ key: 'shortName', value: 'companyoverview' }] }),
            ['CompanySearch', 'Research', 'LRTM', 'Portfolio', 'Pager', 'ScrollPager', 'Company', 'GCCS.Security', 'PI.Security', 'ScreeningTool.Security'])

            .when('/research/overview/:companyName',
            {
                templateUrl: '/views/Research/CompanyOverview/Company.html', controller: 'CompanyOverviewController'
            },
            null,
            ['CompanySearch', 'LRTM', 'CompanyOverview', 'Pager', 'ScrollPager', 'Research', 'Company', 'GCCS.Security', 'PI.Security', 'ScreeningTool.Security'])

            .when('/research/globalcompact/company/:companyName/:overallAssessment?',
            {
                templateUrl: '/views/Research/GlobalCompact/Company.html', controller: 'GCCompanyController'
            },
            new Routing.RouteSecurity().addService('GCRouteSecurityService'),
            ['CompanySearch', 'LRTM', 'Research', 'GCCS', 'Pager', 'ScrollPager', 'Company', 'GCCS.Security', 'PI.Security', 'ScreeningTool.Security'])

            .when('/research/pi',
            {
                templateUrl: '/views/Research/ProductInvolvement/CompanyAssessmentList.html', controller: 'CompanyAssessmentListController'
            },
            new Routing.RouteSecurity().addService('PIMultiCompanyRouteSecurityService'),
            ['CompanySearch', 'LRTM', 'Research', 'PI', 'Pager', 'ScrollPager', 'Company', 'GCCS.Security', 'PI.Security', 'ScreeningTool.Security'])

            .when('/research/globalcompact/:overallAssessment?',
            {
                templateUrl: '/views/Research/GlobalCompact/MultiCompanyReport.html', controller: 'GCMultiCompanyReportController'
            },
            new Routing.RouteSecurity().addService('GCMultiCompanyRouteSecurityService'), 
            ['CompanySearch', 'LRTM', 'GCCS', 'Research', 'Pager', 'ScrollPager', 'Company', 'GCCS.Security', 'PI.Security', 'ScreeningTool.Security'])

            .when('/research/pi/:companyName',
            {
                templateUrl: '/views/Research/ProductInvolvement/CompanyAssessmentDetails.html', controller: 'CompanyAssessmentDetailsController'
            },
            new Routing.RouteSecurity().addService('PICompanyRouteSecurityService'),
            ['CompanySearch', 'LRTM', 'PI', 'Research', 'Pager', 'ScrollPager', 'Company', 'GCCS.Security', 'PI.Security', 'ScreeningTool.Security'])

            .when('/research/governance/:companyName',
            {
                templateUrl: '/views/Research/Governance/Company.html', controller: 'GovernanceProfileController', controllerAs: 'governanceProfile'
            },
            new Routing.RouteSecurity().addResource({ verb: 'GET', resource: 'api/v1/governance', parameters: [] }),
            ['CompanySearch', 'LRTM', 'Governance', 'Research', 'Pager', 'ScrollPager', 'Company', 'GCCS.Security', 'PI.Security', 'ScreeningTool.Security'])

            .when('/research/esgRatings/:companyName',
            {
                templateUrl: '/views/Research/EsgRatings/Company.html'
            },
            new Routing.RouteSecurity().addResource({ verb: 'GET', resource: 'api/v1/esgratings/{companyId}', parameters: [] }),
            ['CompanySearch', 'LRTM', 'EsgRatings', 'Research', 'Pager', 'ScrollPager', 'Company', 'GCCS.Security', 'PI.Security', 'ScreeningTool.Security'])

            .when('/research/controversies/:companyName',
            {
                templateUrl: '/views/Research/Controversies/Company.html', controller: 'ControversiesController'
            },
            new Routing.RouteSecurity().addResource({verb: 'GET', resource: 'api/v1/company/{companyId}/esgControversyIndicator', parameters: [] }),
            ['CompanySearch', 'LRTM', 'Controversies', 'Research', 'Pager', 'ScrollPager', 'Company', 'GCCS.Security', 'PI.Security', 'ScreeningTool.Security'])

            .when('/research/:companyName', {
                redirectTo: function (routeParams) {
                    return '/research/overview/' + routeParams.companyName;
                }
            })

            .when('/tools',
            {
                templateUrl: '/views/tools/Tools.html', controller: 'ScreeningToolController'
            },
            new Routing.RouteSecurity().addService('ScreeningToolRouteSecurityService'),
            ['CompanySearch', 'LRTM', 'Pager', 'ScrollPager', 'Company', 'ScreeningTool', 'GCCS.Security', 'PI.Security', 'ScreeningTool.Security'])

            .when('/company/:companyId',
            {
                templateUrl: '/views/Company.html', controller: 'CompanyController'
            },
            null,
            ['CompanySearch', 'LRTM', 'Company', 'Pager', 'ScrollPager', 'GCCS.Security', 'PI.Security', 'ScreeningTool.Security'])

            .when('/lrtmtest',
            {
                templateUrl: '/views/LongRunningTaskManagerTest.html', controller: 'LongRunningTaskManagerTestController'
            },
            null,
            ['CompanySearch', 'LRTMTest', 'GCCS.Security', 'PI.Security', 'ScreeningTool.Security'])

            .when('/forgotPassword',
            {
                templateUrl: '/views/Login/ForgotPassword.html', controller: Sustainalytics.Authentication.accountControllerName
            },
            new Routing.RouteSecurity(),
            [])

            .when('/forgotPasswordConfirmation',
            {
                templateUrl: '/views/Login/ForgotPasswordConfirmation.html', controller: Sustainalytics.Authentication.accountControllerName
            },
            new Routing.RouteSecurity(),
            [])

            .when('/changePassword/:user?/:tempKey?',
            {
                templateUrl: '/views/Login/ChangePassword.html', controller: Sustainalytics.Authentication.accountControllerName
            },
            new Routing.RouteSecurity(),
            [])

            .when('/passwordExpired',
            {
                templateUrl: '/views/Login/PasswordExpired.html', controller: Sustainalytics.Authentication.accountControllerName
            },
            new Routing.RouteSecurity(),
            [])

            //.when('/reports', {
            //    templateUrl: '/views/Reports.html', controller: 'ReportsController'
            //})

            .when('/login',
            {
                templateUrl: '/views/Login/Login.html', controller: Sustainalytics.Authentication.accountControllerName
            },
            new Routing.RouteSecurity().setLogout(true),
            [])

            .otherwise({ redirectTo: '/' });
    }]);


    // add sitemaps on module init
    mod.run(['NavigationService', (NavigationService: Navigation.INavigationService) => {

        // add sitemaps
        SiteMapUtility.addSiteMaps(NavigationService);
    }]);


    // bootstraping
    angular.element(document).ready(function () {
        angular.bootstrap(document, ['shell']);
    });
}